import React, { PureComponent } from "react";

// 父render -> 子render -> 子didmount -> 父didmount
// 默认情况下只要父组件重新渲染了，那么子组件也必定会重新渲染
// 可以通过shouldComponentUpdate里面去返回false来阻止重新渲染
class Child extends PureComponent {
  render() {
    console.log("child render");
    return <div>child子组件</div>;
  }

  componentDidMount() {
    console.log("child didmount");
  }

  // componentWillReceiveProps被废弃了
  // 组件将要接收props
  UNSAFE_componentWillReceiveProps() {
    console.log("componentWillReceiveProps");
  }

  // shouldComponentUpdate(nextProps, nextState) {
  //   return nextProps.name !== this.props.name;
  // }

  UNSAFE_componentWillUpdate() {
    console.log("child UNSAFE_componentWillUpdate");
  }

  componentDidUpdate() {
    console.log("child componentDidUpdate");
  }
}

export default Child;
